from jili.tool.cmdtool import isruns
import os,time,datetime
from jili.core.config import  load_config_json_bypcname
from jili.tool.convert import time2datetime
def get_tasks(dofile,donefile):
    s0=[]
    s1=[]
    s=[]
    with open(donefile) as f1:
        for i in f1:
            if "\n" == i[-1:]:
                i = i[:-1]
            i=i.strip()
            if i!="":
                s0.append(os.path.abspath(i))
    with open(dofile) as f2:
        for i in f2:
            if "\n" == i[-1:]:
                i = i[:-1]
            i = i.strip()
            if i != "":
                i=os.path.abspath(i)
                if i not in s0:
                    s.append(i)
    if s:
        if s0:
            s.append(s0[-1])
        ss=isruns(s)
        if ss[-1]:
            rst = False
        else:
            if True in ss[:-1]:
                rst=False
            else:
                rst = True
    else:
        rst = False
    return rst,s
def run_python(l,donefile):
    cmd = "python " + l
    try:
        print("运行任务",cmd)
        os.system(cmd)
        with open(donefile,"a") as f:
            f.write(l+"\n")
            print("完成任务",l)
            f.close()
    except Exception as e:
        print(e)
def isno_time(no_time):
    rst=False
    if no_time:
        now = datetime.datetime.now()
        r=[time2datetime(no_time[0]),time2datetime(no_time[1])]
        if r[0]>r[1]:
            rst=r[0]<now<r[1]
        else:
            rst=now>r[0] or now<r[1]
    return rst